{extend name="platform/base" /}
{block name="main"}

 <div class="row padder-v">
            <div class="col-sm-9">
              	   <a class="btn btn-sm btn-primary" href="PLATFORM_MAIN/cms/addtopic" ><i class="fa fa-plus"></i>&nbsp;添加专题</a>
            </div>
 </div>
<section class="panel panel-default">
       <div class="table-responsive">
            <table  class="table table-striped b-t b-light text-sm">
				 <thead>
				 <tr>
                    <th width="20"><input type="checkbox"></th>
                    <th class="center">标题</th>
                    <th class="center">状态</th>
                    <th class="center">发布时间</th>
                    <th class="center">操作</th>
				 </tr>
				 <tbody id="list">
				    <tr></tr>
				 </tbody>
			</table>
       </div>
              {include file="platform/page" /}
</section>

{/block}
{block name="script"}
<script type="text/javascript">
//分页数据
$(function(){
	LoadingInfo(1);
});
function LoadingInfo(page_index) {
	var search_text = $("#search_text").val();
	$.ajax({
		type : "post",
		url : "PLATFORM_MAIN/cms/topiclist",
		async : true,
		data : {
			"page_index" : page_index,  "search_text" : search_text
		},
		success : function(data) {
		//	alert(JSON.stringify(data));
			var html = '';
			$("#total_count_num").text(data["total_count"]);
			$("#page_count_num").text(data["page_count"]);
			$("#page_count").val(data["page_count"]);
			$("#pageNumber a").remove();
			if (data["data"].length > 0) {
				for (var i = 0; i < data["data"].length; i++) {
					html += '<tr align="center">';
					html += '<td><div class="cell"><label><input name="sub" type="checkbox" value="'+ data['data'][i]['topic_id']+'" ></label></div></td>';
					//html += '<td><input type="number" min="0" value="'+ data["data"][i]["topic_id"]+'"  fieldid="'+ data['data'][i]['topic_id']+'" class="num" ></td>';	
					html += '<td class="tal" title="'+data["data"][i]["title"]+'">' + data["data"][i]["title"]+ '</td>';
					if(data["data"][i]["status"]==0){
						html += '<td>未发布</td>';	
					}else{ 
						html += '<td>已发布</td>';
					}
					html += '<td>' + data["data"][i]["create_time"]+ '</td>';
					html += '<td><a target="_blank" href="SHOP_MAIN/topic/detail?topic_id='+ data['data'][i]['topic_id']+'">预览</a>&nbsp;&nbsp;<a href="PLATFORM_MAIN/cms/updatetopic?id='+ data['data'][i]['topic_id']+'">修改</a>&nbsp;&nbsp;<a style="cursor: pointer;" onclick="deleteTopic('+data['data'][i]['topic_id']+')">删除</a></td> ';
					html += '</tr>';
				}
			} else {
				html += '<tr align="center"><th colspan="9">暂无专题</th></tr>';
			}
			$("#list").html(html);
			var totalpage = $("#page_count").val();
			if (totalpage == 1) {
				changeClass("all");
			}
			var $html = pagenumShow(jumpNumber,totalpage,{$pageshow})
			$("#pageNumber").append($html);
			load();
		}
	});
}	

function batchDelete() {
	var topic_id= new Array();
	$(".style0list tbody input[type='checkbox']:checked").each(function() {
		if (!isNaN($(this).val())) {
			topic_id.push($(this).val());
		}
	});
	if(topic_id.length ==0){
		$( "#dialog" ).dialog({
			buttons: {
				"确定,#e57373": function() {
					$(this).dialog('close');
				}
			},
			contentText:"请选择需要操作的记录",
			title:"消息提醒",
		});
		return false;
	}
	deleteTopic(topic_id);
}
var flag = false;
//删除
function deleteTopic(topic_id){
	$( "#dialog" ).dialog({
		buttons: {
			"确定": function() {
				$(this).dialog('close');
				if(!flag){
					flag = true;
					$.ajax({
						type : "post",
						url : "PLATFORM_MAIN/cms/deletetopic",
						data : {
							"topic_id" : topic_id.toString()
						},
						dataType : "json",
						success : function(data) {
							if (data["code"] > 0) {
								showMessage('success', data["message"]);
								location.href="PLATFORM_MAIN/cms/topiclist";
							}else{
								showMessage('error', data["message"]);
							}
							flag = false;
						}
					})
				}
			},
			"取消,#e57373": function() {
				$(this).dialog('close');
			}
		},
	contentText:"是否删除专题？",
	});
}

/*修改排序*/
function load(){
	$('.num').change(function(){
		var fieldid = $(this).attr('fieldid');
		var sort = $(this).val();
		$.ajax({
			type:"post",
			url:"PLATFORM_MAIN/cms/modifyarticlefield",
			data:{'fieldid':fieldid,'sort':sort},
			async:true,
			success: function (data) {
				if(data['code'] <= 0){
					showMessage('error', data["message"]);
				}
			}
		});
	});
}
//全选
function CheckAll(event){
	var checked = event.checked;
	$(".style0list tbody input[type = 'checkbox']").prop("checked",checked);
}
</script>
{/block}